package com.wc.codeforces.总结题.Graph_Composition;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2025/5/4 20:41
 * @description
 * https://codeforces.com/contest/2060/problem/E
 */
public class Main {
    /**
     * 思路：
     * 求交集
     * 然后 m1 + m2 - 2 * 交集个数
     * 理解错题意，等后续再说
     */
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 400010;
    static long[] f1 = new long[N], f2 = new long[N];
    static int n, m1, m2;

    public static void main(String[] args) {
        int T = sc.nextInt();
        while (T-- > 0) {
            n = sc.nextInt();
            m1 = sc.nextInt();
            m2 = sc.nextInt();
            for (int i = 1, j = 1; i <= m1; i++) {
                long a = sc.nextInt(), b = sc.nextInt();
                f1[j++] = a * N + b;
                f1[j++] = b * N + a;
            }
            for (int i = 1, j = 1; i <= m2; i++) {
                long a = sc.nextInt(), b = sc.nextInt();
                f2[j++] = a * N + b;
                f2[j++] = b * N + a;
            }

            Arrays.sort(f1, 1, 2 * m1 + 1);
            Arrays.sort(f2, 1, 2 * m2 + 1);
            int i = 1, j = 1;
            int eq = 0;
            while (i <= 2 * m1 && j <= 2 * m2) {
                if (f1[i] == f2[j]) {
                    eq++;
                    i++;
                    j++;
                } else if (f1[i] < f2[j]) i++;
                else j++;
            }
            int res = m1 + m2 - eq;
            out.println(res);
        }
        out.flush();
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}

